package com.cat.dao.common.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.cat.bean.common.PageBean;
import com.cat.dao.common.UserDao;
import com.cat.entity.TbUser;

/**
 * @ClassName: ExecutionContextDaoImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author Jiangcl
 * @date 2012-2-21下午12:38:36
 * 
 */
@Repository
@SuppressWarnings("unchecked")
public class UserDaoImpl extends BaseDaoImpl<TbUser, Integer> implements UserDao {
	
	
	public List<TbUser> getUserList(TbUser user, PageBean page) {
		Criteria c = getSession().createCriteria(TbUser.class);
		if(user.getUserName()!=null&&!user.getUserName().equals("")){
		   c.add(Restrictions.ilike("userName", "'%"+user.getUserName()+"%'"));
		}
		c.setFirstResult(Integer.parseInt(page.getTotalRows()));
		c.setMaxResults(Integer.parseInt(page.getPageSize()));
		if(c.list()!=null){
			return c.list();
		}
		return null; 
	}

	@Override
	public TbUser checkUserInfo(TbUser user) {
		Criteria c = getSession().createCriteria(TbUser.class);
		c.add(Restrictions.and(Restrictions.eq("accountNo", user.getAccountNo()), 
				Restrictions.eq("userPassword", user.getUserPassword())));
		if(c.list()!=null&&c.list().size()>0){
			return (TbUser) c.list().get(0);
		}
		return null;
	}

	@Override
  public List<TbUser> getUserListByRoleId(String roleId) {
		Criteria c = getSession().createCriteria(TbUser.class);
		c.add(Restrictions.eq("userType", Integer.valueOf(roleId)));
		if(c.list()!=null){
			return c.list();
		}
		return null;
  }
	
}
